home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / tcptimer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.2 KB  |  57 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. int tcptimertype = 0;        /* default backoff to binary exponential */
  11.  
  12. /* Timer timeout */
  13. void
  14. tcp_timeout(p)
  15. void *p;
  16. {
  17.     register struct tcb *tcb;
  18.  
  19.     tcb = p;
  20.     if(tcb == NULLTCB)
  21.         return;
  22.  
  23.     /* Make sure the timer has stopped (we might have been kicked) */
  24.     stop_timer(&tcb->timer);
  25.  
  26.     switch(tcb->state){
  27.     case TCP_TIME_WAIT:    /* 2MSL timer has expired */
  28.         close_self(tcb,NORMAL);
  29.         break;
  30.     default:        /* Retransmission timer has expired */
  31.         tcb->flags.retran = 1;    /* Indicate > 1  transmission */
  32.         tcb->backoff++;
  33.         tcb->snd.ptr = tcb->snd.una;
  34.         /* Reduce slowstart threshold to half current window */
  35.         tcb->ssthresh = tcb->cwind / 2;
  36.         tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  37.         /* Shrink congestion window to 1 packet */
  38.         tcb->cwind = tcb->mss;
  39.         tcp_output(tcb);
  40.     }
  41. }
  42.  
  43. /* Backoff function - the subject of much research */
  44. int32
  45. backoff(n)
  46. int n;
  47. {
  48.     if(n > 31)
  49.         n = 31;    /* Prevent truncation to zero */
  50.  
  51.     if(tcptimertype)
  52.         return (int32) ++n;    /* Linear backoff for sensible values! */
  53.     else
  54.         return 1L << n;    /* Binary exponential back off */
  55. }
  56.  
  57.